package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.pojo.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import javax.print.Doc;
import java.util.HashMap;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private JwtProperties jwtProperties;

    /**
     * @return a
     * @description
     * @author shd
     * @date 2025/1/19 9:46
     * @params
     */
    @PostMapping("/login")
    @ApiOperation("员工登录")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        log.info("员工登录：{}", employeeLoginDTO);
        return employeeService.login(employeeLoginDTO);
        //登录成功后，生成jwt令牌
        // Map<String, Object> claims = new HashMap<>();
        // claims.put(JwtClaimsConstant.EMP_ID, employee.getId());
        // String token = JwtUtil.createJWT(
        //         jwtProperties.getAdminSecretKey(),
        //         jwtProperties.getAdminTtl(),
        //         claims);
        // EmployeeLoginVO employeeLoginVO = EmployeeLoginVO.builder()
        //         .id(employee.getId())
        //         .userName(employee.getUsername())
        //         .name(employee.getName())
        //         .token(token)
        //         .build();
        // return Result.success(employeeLoginVO);
    }


    @PostMapping
    @ApiOperation("新增员工")
    public Result<String> add(@RequestBody EmployeeDTO employeeDTO) {
        log.info("{}",employeeDTO);
        return employeeService.add(employeeDTO);
    }


    /**
     * @description 员工退出
     * @author shd
     * @date 2025/1/19 9:24
     */
    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result<String> logout() {
        return Result.success();
    }

    /**
     * @description 员工列表查询
     * @author shd
     * @date 2025/1/19 9:23
     * @params 分页查询参数
     * @return 结果
     */
    @GetMapping("/page")
    @ApiOperation("员工列表查询")
    public Result<PageResult> pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
        log.info("{}", employeePageQueryDTO);
        return employeeService.pageQuery(employeePageQueryDTO);
    }

    /**
     * @description
     * @author shd
     * @date 2025/1/19 19:52
     * @params status 员工状态 id 员工id
     * @return 结果
     */
    @ApiOperation("员工状态更新")
    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable Integer status, long id) {
        log.info("{}, {}", status, id);
        return employeeService.startOrStop(status, id);
    }

    /**
     * @description 员工数据回显
     * @author shd
     * @date 2025/1/19 20:20
     * @params 员工id
     * @return 结果
     */
    @ApiOperation("员工数据回显")
    @GetMapping("/{id}")
    public Result<Employee> findById(@PathVariable Integer id) {
        log.info("员工id是{}", id);
        return employeeService.findById(id);
    }

    /**
     * @description
     * @author shd
     * @date 2025/1/19 20:34
     * @params employee 员工信息
     * @return 结果
     */
    @ApiOperation("修改员工数据")
    @PutMapping
    public Result<String> update(@RequestBody Employee employee) {
        log.info("员工信息是{}", employee);
        return employeeService.update(employee);
    }




}

